package com.ibm.ops.parser;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.log4j.Logger;

import com.ibm.ops.OpstoolConstant;
import com.ibm.ops.domain.report.OpsAuditLogHubReport;
import com.ibm.ops.exception.RetrieveReportDataException;
import com.ibm.ops.persistent.PersistentHandler;

class HubReportParser extends ParserTemplate {

	private static Logger logger = Logger.getLogger(HubReportParser.class);
	
	public HubReportParser(PersistentHandler persistentHanlder){
		super(persistentHanlder);
		this.report = new OpsAuditLogHubReport();
	}
	
//	@Override
//	protected OpsAuditLogReport createReport() throws CreateReportException{
//		return new OpsAuditLogHubReport();
//	}

	@Override
	protected List<String> retrieveReportData(String rawContent) throws RetrieveReportDataException{
		List<String> result = new ArrayList<String>();
		try{
			String[] content = rawContent.split(OpstoolConstant.HUB_REPORT_SPLIT_TAG);
			if(content.length < 3){
				throw new RetrieveReportDataException("There is no Hub report data today.");
			}
			String[] usefulData = content[1].split(OpstoolConstant.SYSTEM_LINE_SEPARATOR);
			result = Arrays.asList(usefulData);
		}catch(RuntimeException e){
			logger.error("Error happened when retieve hub report data." + e.getMessage());
			logger.error(e.getStackTrace());
			throw new RetrieveReportDataException("Error happened when retieve hub report data.");
		}
		return result;
	}

}
